package ph.com.gs3.formalistics.services;

import java.util.ArrayList;
import java.util.List;

import ph.com.gs3.formalistics.model.rdao.FilesRDAO;
import ph.com.gs3.formalistics.model.rdao.FilesRDAO.FileUploadFailedException;
import ph.com.gs3.formalistics.model.vo.business.User;
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;

public class UploadService extends IntentService {

	public static final String TAG = UploadService.class.getSimpleName();
	public static final String NAME = UploadService.class.getName();

	public static final String EXTRA_FILE_URI = "file_uri";
	public static final String EXTRA_OWNER = "owner";

	private FilesRDAO filesRDAO;
	private User fileOwner;

	public UploadService() {
		super(NAME);
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		Bundle extras = intent.getExtras();
		fileOwner = (User) extras.getSerializable(EXTRA_OWNER);

		String fileURI = extras.getString(EXTRA_FILE_URI);
		String destinationFolder = "attachment";

		List<String> fileURIList = new ArrayList<>();
		fileURIList.add(fileURI);

		filesRDAO = new FilesRDAO(fileOwner.getCompany().getServer());
		try {
//			filesRDAO.uploadFiles(fileURIList, destinationFolder);
			filesRDAO.uploadFilesTest(fileURIList, destinationFolder);
		} catch (FileUploadFailedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
